package com.bsj.power.job.web.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.def.dto.PageDTO;
import com.bsj.power.common.def.entity.exp.TrainPlan;
import com.bsj.power.common.def.dto.job.CourseDTO;
import com.bsj.power.common.def.dto.job.TrainPlanDTO;
import com.bsj.power.job.service.TrainPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 培训计划
 * @date 2024/5/28
 */
@RestController
@RequestMapping("/train")
//@SaCheckPermission("/job/train")
public class TrainPlanController {

    @Autowired
    private TrainPlanService trainPlanService;

    /**
     * 新增和修改培训计划
     * @param dto
     * @return
     */
    @PostMapping("/doPlanAddAndUpdate")
    public JsonResult doPlanAddAndUpdate(@RequestBody TrainPlanDTO dto) {
        return trainPlanService.addAndUpdate(dto);
    }

    /**
     * 分页获取培训计划列表
     * @param dto
     * @return
     */
    @GetMapping("/doPlanPageList")
    public JsonResult<List<TrainPlan>> doPlanPageList(PageDTO dto) {
        return trainPlanService.pageList(dto);
    }

    /**
     * 根据ID获取培训计划信息
     * @param trainId
     * @return
     */
    @GetMapping("/doPlanFindIdByInfo")
    public JsonResult<TrainPlan> doPlanFindIdByInfo(Long trainId) {
        if (trainId == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return trainPlanService.findIdByInfo(trainId);
    }

    /**
     * 批量删除培训计划
     * @param dto
     * @return
     */
    @PostMapping("/doPlanDelete")
    public JsonResult<Integer> doPlanDelete(@RequestBody TrainPlanDTO dto) {
        Long[] trainIds = dto.getTrainIds();
        if (trainIds == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return trainPlanService.deleteExp(trainIds);
    }

    /**
     * 新增或修改培训课程
     * @param dto
     * @return
     */
    @PostMapping("/doAddUpdateCourse")
    public JsonResult doAddUpdateCourse(@RequestBody CourseDTO dto) {
        return trainPlanService.addAndUpdateCourse(dto);
    }

    /**
     * 删除培训课程
     * @param dto
     * @return
     */
    @PostMapping("/doDeleteCourse")
    public JsonResult<Integer> doDeleteCourse(@RequestBody CourseDTO dto) {
        Long[] courseIds = dto.getCourseIds();
        if (courseIds == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return trainPlanService.deleteCourse(courseIds);
    }
}
